<?php
$objXajax->registerFunction("frmreportcustomer_load");
$objXajax->registerFunction("frmreportcustomer_init");
  
 function  frmreportcustomer_init(){
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax      
    $fromdate = SYSTEM_DATE;  
    $todate = SYSTEM_DATE; 
    $objResponse->addScript("$('#frmreportcustomer_fromdate').val('$fromdate')"); 
    $objResponse->addScript("$('#frmreportcustomer_todate').val('$todate')");     
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax           
 }

function frmreportcustomer_load($dateFrom,$dateTo,$room=''){     

    global $lang,$path;
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax
    $arrData = frmreportcustomer_createArray($dateFrom,$dateTo,$room);
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('../templates/'.$lang.'/'.$path.'/hotel_reportcustomer_grid.html');
    $oTbs->MergeBlock('blk_data', $arrData); 
    $oTbs->Show(TBS_NOTHING);  
    $objResponse->addAssign('frmreportcustomer_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('frmreportcustomer_tbl');");  
    $objResponse->addScript('changeWaiting(1);');                     
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax   
}

function frmreportcustomer_createArray($dateFrom,$dateTo,$room=''){
    global $objDbUpdate,$tbl_postfix;
    $addCondition = '';
    if($room!=''){
      $addCondition= " and h.room_id = '$room' ";  
    }
    $sql = " select r.name as roomname,h.timebegin as timebegin,h.timeend as timeend,c.*,if(c.sex=0,'Nam','Nữ') as sex1
    from tbl_history_book_room$tbl_postfix as h join tbl_room$tbl_postfix r ON h.room_id = r.id join tbl_customer$tbl_postfix as c 
    ON c.generate_id = h.generate_id 
    where  datediff('$dateFrom',h.timeend)<=0 and datediff('$dateTo',h.timeend)>=0 $addCondition ";//
    $arr = $objDbUpdate->GetArray($sql);    
    return  $arr  ;
} 

# end region process data
?>
